package com.zhuoxin.dao.admin;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

import com.zhuoxin.bean.model.Company;
import com.zhuoxin.bean.model.Job;
import com.zhuoxin.bean.model.JobSO;
import com.zhuoxin.dao.BaseDAOImpl;

public class JobDAOImpl extends BaseDAOImpl<Job, JobSO> implements JobDAO {

	@Override
	public String getHqlWhere(JobSO so) {
		return null;
	}

	@Override
	public void setCriteriaParams(Criteria criteria, JobSO so) {
		if(so.getCompany()!=null){
			criteria.createAlias("company", "c");
			
			if(so.getCompany().getId()!=null){
				criteria.add(Restrictions.eq("c.id", so.getCompany().getId()));
			}
			
			if(StringUtils.isNotEmpty(so.getCompany().getName())){
				criteria.add(Restrictions.ilike("c.name", "%"+StringUtils.trim(so.getCompany().getName())+"%"));
			}
		}
		
		if(StringUtils.isNotEmpty(so.getName())){
			criteria.add(Restrictions.ilike("name", "%"+StringUtils.trim(so.getName())+"%"));
		}
		
		if(so.getSalary()!=null){
			criteria.add(Restrictions.eq("salary",so.getSalary()));
		}
		
		if(so.getExperience()!=null){
			criteria.add(Restrictions.eq("experience",so.getExperience()));
		}
		
		if(so.getAge()!=null){
			criteria.add(Restrictions.eq("age",so.getAge()));
		}
		
		if(so.getSex()!=null){
			criteria.add(Restrictions.eq("sex",so.getSex()));
		}
		
		if(so.getDegree()!=null){
			criteria.add(Restrictions.eq("segree",so.getDegree()));
		}
		
		if(so.getWorkType()!=null){
			criteria.add(Restrictions.eq("workType",so.getWorkType()));
		}
	}

	@Override
	public void setQueryParams(Query query, JobSO so) {
		
	}

	@Override
	public void switchVO2PO(Job po, JobSO so) {
		if(StringUtils.isNotEmpty(so.getName())){
			po.setName(StringUtils.trim(so.getName()));
		}
		
		if(StringUtils.isNotEmpty(so.getCaption())){
			po.setCaption(StringUtils.trim(so.getCaption()));
		}
		
		
		if(StringUtils.isNotEmpty(so.getDemand())){
			po.setDemand(StringUtils.trim(so.getDemand()));
		}
		
		if(so.getSalary()!=null){
			po.setSalary(so.getSalary());
		}
		
		if(so.getExperience()!=null){
			po.setExperience(so.getExperience());
		}
		
		if(so.getAge()!=null){
			po.setAge(so.getAge());
		}
		
		if(so.getSex()!=null){
			po.setSex(so.getSex());
		}
		
		if(so.getDegree()!=null){
			po.setDegree(so.getDegree());
		}
		
		if(so.getWorkType()!=null){
			po.setWorkType(so.getWorkType());
		}
		
		if(so.getAmount()!=null){
			po.setAmount(so.getAmount());
		}
		
		if(StringUtils.isNotEmpty(so.getStopTime())){
			po.setStopTime(StringUtils.trim(so.getStopTime()));
		}
		
		if(so.getCompany()!=null && so.getCompany().getId()!=null){
			Company company=findById(Company.class, so.getCompany().getId());
			po.setCompany(company);
		}		
	}



}
